<!-- 整改方案--提交审批记录 -->
<template>
  <div class='lanjian-content custom'>
    <div class="tableOperator">
      <div></div>
      <div>
        <span style="font-size: 18px;color: #333;">提交时间: </span>
        <a-range-picker v-model:value="history2e" class='m-r-8' :format="dateFormatList" />
        <a-button type='primary' class='m-r-8 ClassA' @click='search' title='搜索'>
          <span class='icon iconfont'>&#xe666;</span>
        </a-button>
        <a-button class='resBtn ClassA' @click='loadtable' title='重置'>
          <span class='icon iconfont'>&#xe672;</span>
        </a-button>
    </div>
    </div>
    <a-table
      class="table-box"
      :columns="columns"
      :data-source="dataSource"
      :pagination="pagination"
      @change="tablePaginationChange"
      :key=" getNowMilliSecond"
      :scroll="{x: '100%', y: 'calc( 103vh - 350px )'}"
    >
        <span
          slot="action"
          slot-scope="record"
          class="actionbtn">
          <span @click="see(record)">查看</span>
        </span>
      <span
        slot="files"
        slot-scope="record"
        class="actionbtn">
        <ui v-for="(item,index) in record" :key="index" :value="item.value" @click="downtmp(item.tfpath,item.tfname)">
          <li><a >{{item.tfname}}</a></li>
        </ui>
        </span>
    </a-table>
  </div>
</template>

<script>
import {
  getRectificationPlanSpjl,
} from '@/utils/index';
import moment from 'moment';
import {getZGBGHistory, getZGFAHistory, getZGGKHistory} from "@/utils/fileUtils";
import {formatDate, getLDType, getNowMilliSecond, getZGType} from "@/utils/common";
import {forEach} from "core-js/stable/dom-collections";
import fs from "fs";
import {streamToBuffer} from "@/utils/JsonTools";

export default {
  name: 'ApprovalHistory',
  data() {
    return {
      history2e:[],
      dateFormatList:'YYYY/MM/DD',
      // 列
      columns: [
        {
          dataIndex: 'ID_',
          key: 'ID_',
          title: '序号',
          width: 70,
          align: 'center',
          customRender: (text, record, index) => `${index + 1}`,
        },
        {
          title: '提交时间',
          dataIndex: 'F_FSSJ_',
          key: 'F_FSSJ_',
          align: 'center',
          ellipsis: true,
        },
        {
          title: '评审意见',
          dataIndex: 'F_SPYJ_',
          key: 'F_SPYJ_',
          align: 'center',
          customRender: (text, record, index) => {
            // eslint-disable-next-line no-empty,no-undef
            return getLDType(record.F_SPYJ_);
          }
        },
        {
          title: '审批说明',
          dataIndex: 'F_SPSM_',
          key: 'F_SPSM_',
          align: 'center',
          ellipsis: true,
        },
        {
          title: '附件',
          dataIndex: 'gkfj',
          key: 'gkfj',
          align: 'center',
          ellipsis: true,
          width: 300,
          scopedSlots: { customRender: 'files' }
        },
        {
          title: '审核单位',
          dataIndex: 'F_SHDWMC_',
          key: 'F_SHDWMC_',
          align: 'center',
          ellipsis: true,
        },
        {
          title: '评审时间',
          dataIndex: 'F_SPSJ_',
          key: 'F_SPSJ_',
          align: 'center',
          ellipsis: true,
        },
      ],
      dataSource: [],
      queryParam: {
        attr: [],
      },
      // 分页参数
      pagination: {
        current: 1,
        // defaultCurrent: 1,
        total: 0, // 总数
        showSizeChanger: true,
        // 是否可以快速跳转至某页
        showQuickJumper: true,
        pageSizeOptions: ['10', '20', '40', '80', '100'],
        // showTotal: total => '共 ${total} 条', // 分页中显示总的数据
        // hideOnSinglePage: true, // 只有一页时是否隐藏分页器
        pageSize: 10, // 每页条数，所有页设置统一的条数
      },
    };
  },
  mounted() {
    this.loadtable()
  },
  methods: {
    getNowMilliSecond,
    moment,
    // 搜索时间选择器
    onChange(date, dateString) {
      this.queryParam.attr = [...dateString];
    },
    tablePaginationChange(pagination) {
      // 重新设置当前页
      this.pagination.current = pagination.current;
      this.pagination.pageSize = pagination.pageSize;
    },
    // 查询反馈意见
    loadtable() {
      this.queryParam.attr = [];
      this.history2e=[]
      getZGGKHistory().then(res => {
        console.log("fa---",res)
        res.sort((a, b) => {
          const date1=new Date(a.F_SPSJ_).getTime()
          const date2=new Date(b.F_SPSJ_).getTime()
          if(date1<date2){
            return 1
          }else{
            return -1
          }
        })
        this.dataSource = [...res];
      });
    },
    search() {
      getZGGKHistory().then(res => {
        console.log("fa-121--",res)
        let arr = [];
        res.forEach(element => {
          if(this.history2e.length>0){
            let datel = formatDate(new Date(Date.parse(element.F_FSSJ_.split(" ")[0])), 'Y-M-D')
            //if (this.queryParam.attr.length > 0 && this.queryParam.attr[0] != '') {
            let  dates = formatDate(new Date(Date.parse(this.history2e[0])), 'Y-M-D')
            let  datee = formatDate(new Date(Date.parse(this.history2e[1])), 'Y-M-D')
            if (dates <= datel && datel <= datee) {
              arr.push(element);
            }
          }else{
            arr.push(element);
          }
        });
        arr.sort((a, b) => {
          const date1=new Date(a.F_SPSJ_).getTime()
          const date2=new Date(b.F_SPSJ_).getTime()
          if(date1<date2){
            return 1
          }else{
            return -1
          }
        })
        this.dataSource = [...arr];
      });
    },
    /*查看*/
    see(){

    },
  downtmp(path,name){
    let fileb = fs.createReadStream(path);
    let fsname = name;
    console.log('fsname-----' + fsname);
    streamToBuffer(fileb).then(res => {
      let data = res;
      let contents = new Uint8Array(data.length);
      for (let i = 0; i < data.length; i++) {
        contents[i] = data[i];
      }
      // eslint-disable-next-line no-undef
      let expname = fsname;
      saveAs.saveAs(new Blob([contents], { type: 'application/zip' }), expname);
    });
  }
  },
};
</script>
<style lang="less" scoped>
.custom {
  height: calc(100vh - 200px);
}
</style>
